package dnl.confij;

import java.io.File;

/**
 * A base class for configuration sources that adds some basic common features
 * such as time marks.
 * 
 * @author Daniel Or
 * 
 */
public abstract class BaseConfigurationSource implements ConfigurationSource {

	private long lastLoadTimeMillis;

	private long lastSaveTimeMillis;

	private File configFile;

	public BaseConfigurationSource(File configFile) {
		this.configFile = configFile;
	}

	protected abstract void loadConfigurationImpl(Configuration config) throws ConfigException;

	protected abstract void saveConfigurationImpl(Configuration config) throws ConfigException;

	public File getConfigFile() {
		return configFile;
	}

	public void loadConfiguration(Configuration config) throws ConfigException {
		lastLoadTimeMillis = System.currentTimeMillis();
		loadConfigurationImpl(config);
	}

	public void saveConfiguration(Configuration config) throws ConfigException {
		lastSaveTimeMillis = System.currentTimeMillis();
		saveConfigurationImpl(config);
	}

	public long getLastLoadTimeMillis() {
		return lastLoadTimeMillis;
	}

	public void setLastLoadTimeMillis(long lastLoadTimeMillis) {
		this.lastLoadTimeMillis = lastLoadTimeMillis;
	}

	public long getLastSaveTimeMillis() {
		return lastSaveTimeMillis;
	}

	public void setLastSaveTimeMillis(long lastSaveTimeMillis) {
		this.lastSaveTimeMillis = lastSaveTimeMillis;
	}

}
